package com.fh.alipay.controller;

import com.fh.alipay.vo.ApiResult;
import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import com.fh.alipay.po.LqiMerchant;
import com.fh.alipay.service.ILqiMerchantService;
import com.fh.alipay.model.dto.LqiMerchantDTO;
import com.fh.alipay.model.vo.LqiMerchantVO;
import com.fh.alipay.model.query.LqiMerchantQuery;
import com.fh.alipay.model.convert.LqiMerchantConvert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.time.LocalDateTime;
import java.util.Arrays;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author fh
 * @date 2022-05-03
 * @description 猎奇商户控制器
 */
@RestController
@RequestMapping("/aliPay/lqiMerchant")
public class LqiMerchantController extends BaseController {

    @Resource
    private ILqiMerchantService lqiMerchantService;


    /**
     * 获取猎奇商户分页列表
     */
    @GetMapping(value = "/list")
    public ApiResult<IPage<LqiMerchant>> list( LqiMerchantQuery query, Page page) {
        IPage<LqiMerchant> resultPage = lqiMerchantService.getWithPage(page, query);
        return ApiResult.ok(resultPage);
    }

    /**
     * 根据ID获取猎奇商户详情
     */
    @GetMapping("/get")
    public ApiResult<LqiMerchantVO> get(@RequestParam("id") Long id) {
        LqiMerchant entity = lqiMerchantService.getById(id);
        LqiMerchantVO vo = LqiMerchantConvert.toVO(entity);
        return ApiResult.ok(vo);
    }


    /**
     *编辑猎奇商户
     */
    @PostMapping("/update")
    public ApiResult update(@Valid LqiMerchantDTO dto, BindingResult bindingResult) {

        if (bindingResult.hasErrors()) {
            return ApiResult.error("参数不能为空");
        }

        LqiMerchant po = LqiMerchantConvert.toPO(dto);
        po.setUpdateTime(LocalDateTime.now());
        boolean update = lqiMerchantService.updateById(po);
        return update ? ApiResult.ok() : ApiResult.fail();
    }

}
